package com.goresor.model;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;

public class User implements UserDetails {

	private static final long serialVersionUID = 3280512528387999075L;

	private String username;

	private String password;
	private List<GrantedAuthority> listA = new LinkedList<GrantedAuthority>();

	private boolean enabled;

	public User() {
		super();
	}

	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		return listA;
	}

	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public String getUsername() {
		return username;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return enabled;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public void addAuthorities(String[] roles) {
		for (int i = 0; i < roles.length; i++) {
			this.listA.add(new GrantedAuthorityImpl(roles[i]));
		}
	}
}
